package com.fin.zw.intelligentbot.controller;


import com.fin.zw.intelligentbot.annotation.CurrentUser;
import com.fin.zw.intelligentbot.entity.AiConfiguration;
import com.fin.zw.intelligentbot.enums.VoiceType;
import com.fin.zw.intelligentbot.model.request.AiConfigRequest;
import com.fin.zw.intelligentbot.model.session.SessionModel;
import com.fin.zw.intelligentbot.service.AiConfigurationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

@RestController
@RequestMapping("/ai/configuration")
@Api(value = "ai语音配置管理",description = "ai语音配置管理")
public class AiConfigurationController {

    @Autowired
    private AiConfigurationService aiConfigurationService;


    @GetMapping("/fetchPage")
    @ApiOperation(value = "查询所有的ai语音配置信息",notes = "查询所有的ai语音配置信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", dataType = "int", paramType = "query",
                    value = "页数 (0..N)"),
            @ApiImplicitParam(name = "size", dataType = "int", paramType = "query",
                    value = "每页大小."),
            @ApiImplicitParam(name = "sort", allowMultiple = true, dataType = "string", paramType = "query",
                    value = "依据什么排序: 属性名(,asc|desc). ")
    })
    public ResponseEntity<Page<AiConfiguration>> queryAiConfigAll(Pageable pageable,
                                                                  @RequestParam(value = "name",required = false) String name,
                                                                  @RequestParam(value = "type", required = false) VoiceType type,
                                                                  @ApiIgnore @CurrentUser SessionModel sessionModel){
        Page<AiConfiguration> page = aiConfigurationService.queryAiConfiguration(pageable, sessionModel, name, type);
        return ResponseEntity.ok().body(page);
    }

    @GetMapping("/fetch")
    @ApiOperation(value = "查询所有的ai语音配置信息", notes = "查询所有的ai语音配置信息")
    public ResponseEntity<List<AiConfiguration>> getAiConfigList(@RequestParam(value = "type", required = false) VoiceType type,
                                                                 @ApiIgnore @CurrentUser SessionModel sessionModel) {
        List<AiConfiguration> list = aiConfigurationService.getAiConfigurationList(sessionModel, type);
        return ResponseEntity.ok().body(list);
    }


    @PostMapping("/add")
    @ApiOperation(value = "ai语音配置信息添加",notes = "ai语音配置信息添加")
    public ResponseEntity<String> createAiConfig(@RequestBody AiConfigRequest request,
                                                 @ApiIgnore @CurrentUser SessionModel sessionModel){
        aiConfigurationService.createAiConfig(request,sessionModel);
        return ResponseEntity.ok().body("操作成功");
    }

    @RequestMapping(value = "/update",method = {RequestMethod.PUT,RequestMethod.PATCH})
    @ApiOperation(value = "ai语音配置信息更新",notes = "ai语音配置信息更新")
    public ResponseEntity<String> updateAiConfig(@RequestBody AiConfigRequest request,
                                                 @ApiIgnore @CurrentUser SessionModel sessionModel){
        aiConfigurationService.updateAiConfig(request,sessionModel);
        return ResponseEntity.ok().body("操作成功");
    }
}
